package com.taplinker.client.im.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.taplinker.client.im.activity.message.ChatMessageFactory;
import com.taplinker.client.im.activity.message.MessageTypeEnum;
import com.taplinker.client.im.protocol.TapLinkerMessage;

public class ChatListAdapter extends BaseAdapter {
	private Context context;
	public List<TapLinkerMessage> dataList = null;
	
	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public ChatListAdapter() {
		super();
	}

	public ChatListAdapter(Context context, List<TapLinkerMessage> data) {
		this.context = context;
		dataList = data;
	}

	public int getCount() {
		return dataList.size();
	}

	@Override
	public int getViewTypeCount() {
		return MessageTypeEnum.values().length;
	}
	
	@Override
	public int getItemViewType(int position) {
		return MessageTypeEnum.getMessageType((TapLinkerMessage) getItem(position)).getTypeNo();
	}

	public long getItemId(int position) {
		return position;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		return ChatMessageFactory.getMessageView(context, dataList.get(position), convertView);
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}
	
}